<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="证书编号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入证书编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="企业名称" prop="company">
        <el-input
          v-model="queryParams.company"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="手机" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['member:estatecert:remove']"
        >删除</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="estatecertList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"  />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="会员id" align="center" prop="memId"   v-if="false" />
      <el-table-column label="证书编号" width="300" align="center" prop="code" />
      <el-table-column label="二维码编号" align="center" prop="qrcode"  v-if="false"  />
      <el-table-column label="会员名称" align="center" prop="name" />
      <el-table-column label="会员手机" align="center" prop="mobile" />
      <el-table-column label="企业名称" align="center" prop="company" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="单元号" align="center" prop="roomNo" />
      <el-table-column label="权利类型" align="center" prop="ownerType"   v-if="false"  />
      <el-table-column label="权利性质" align="center" prop="ownerProperty"  v-if="false"  />
      <el-table-column label="用途" align="center" prop="purpose"  v-if="false"  />
      <el-table-column label="面积" align="center" prop="area" />
      <el-table-column label="使用期限" align="center" prop="usefulPeriod"  v-if="false" />
      <el-table-column label="其他状况" align="center" prop="othersRemark"  v-if="false"  /> 
      <el-table-column label="其他状况" align="center" prop="status"  v-if="false"  />
      <el-table-column label="纸张数量" align="center" prop="paperCount"  v-if="false"  />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['member:estatecert:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改不动产管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="会员id" prop="memId">
          <el-input v-model="form.memId" placeholder="请输入会员id" />
        </el-form-item>
        <el-form-item label="证书编号" prop="code">
          <el-input v-model="form.code" placeholder="请输入证书编号" />
        </el-form-item>
        <el-form-item label="二维码编号" prop="qrcode">
          <el-input v-model="form.qrcode" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="不动产证路径" prop="url">
          <el-input v-model="form.url" placeholder="请输入不动产证路径" />
        </el-form-item>
        <el-form-item label="权利人" prop="owner">
          <el-input v-model="form.owner" placeholder="请输入权利人" />
        </el-form-item>
        <el-form-item label="共有情况" prop="ownership">
          <el-input v-model="form.ownership" placeholder="请输入共有情况" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="单元号" prop="roomNo">
          <el-input v-model="form.roomNo" placeholder="请输入单元号" />
        </el-form-item>
        <el-form-item label="权利类型">
          <el-select v-model="form.ownerType" placeholder="请选择权利类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="权利性质" prop="ownerProperty">
          <el-input v-model="form.ownerProperty" placeholder="请输入权利性质" />
        </el-form-item>
        <el-form-item label="用途" prop="purpose">
          <el-input v-model="form.purpose" placeholder="请输入用途" />
        </el-form-item>
        <el-form-item label="面积" prop="area">
          <el-input v-model="form.area" placeholder="请输入面积" />
        </el-form-item>
        <el-form-item label="使用期限" prop="usefulPeriod">
          <el-input v-model="form.usefulPeriod" placeholder="请输入使用期限" />
        </el-form-item>
        <el-form-item label="其他状况" prop="othersRemark">
          <el-input v-model="form.othersRemark" placeholder="请输入其他状况" />
        </el-form-item>
        <el-form-item label="其他状况">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="纸张数量" prop="paperCount">
          <el-input v-model="form.paperCount" placeholder="请输入纸张数量" />
        </el-form-item>
        <el-form-item label="类型：1 收费 2 免费">
          <el-select v-model="form.type" placeholder="请选择类型：1 收费 2 免费">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEstatecert, getEstatecert, delEstatecert, addEstatecert, updateEstatecert, exportEstatecert } from "@/api/member/estatecert";

export default {
  name: "Estatecert",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 不动产管理表格数据
      estatecertList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        code: undefined,
        qrcode: undefined,
        company: undefined,
        owner: undefined,
        ownership: undefined,
        address: undefined,
        roomNo: undefined,
        mobile: undefined,
        ownerProperty: undefined,
        purpose: undefined,
        area: undefined,
        usefulPeriod: undefined,
        othersRemark: undefined,
        status: undefined,
        paperCount: undefined,
        type: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { required: true, message: "类型：1 收费 2 免费不能为空", trigger: "blur" }
        ],
        delFlag: [
          { required: true, message: "删除标志（0代表存在 2代表删除）不能为空", trigger: "blur" }
        ],
        createBy: [
          { required: true, message: "创建人不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        paperCount: [
          { required: true, message: "纸张数量不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "类型：1 收费 2 免费不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询不动产管理列表 */
    getList() {
      this.loading = true;
      listEstatecert(this.queryParams).then(response => {
        this.estatecertList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        memId: undefined,
        code: undefined,
        qrcode: undefined,
        url: undefined,
        owner: undefined,
        ownership: undefined,
        address: undefined,
        roomNo: undefined,
        ownerType: undefined,
        ownerProperty: undefined,
        purpose: undefined,
        area: undefined,
        usefulPeriod: undefined,
        othersRemark: undefined,
        status: "0",
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        paperCount: undefined,
        type: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加不动产管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEstatecert(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改不动产管理";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateEstatecert(this.form).then(response => {
              if (response.code == 0) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addEstatecert(this.form).then(response => {
              if (response.code == 0) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除不动产管理序号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delEstatecert(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有不动产管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportEstatecert(queryParams);
        }).then(response => {
          this.download(response.data);
        }).catch(function() {});
    }
  }
};
</script>